﻿using BS.Infra;
using BS.Infra.Interface;
using MediatR;

namespace BS.Read.Api.Handler.Goods
{
    public class ShowGoodsListCommandHandler : IRequestHandler<GetGoodsListCommand, ApiResult>
    {
        private readonly IGoodsRepository _goodsRepository;

        private readonly ILogger<ShowGoodsListCommandHandler> _logger;
        public ShowGoodsListCommandHandler(IGoodsRepository goodsRepository, ILogger<ShowGoodsListCommandHandler> logger)
        {
            _goodsRepository = goodsRepository;
            _logger = logger;
        }
        public async Task<ApiResult> Handle(GetGoodsListCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var ShopGoods=await _goodsRepository.GetAllAsync();
                return  ApiResult.Ok(ShopGoods);
            }
            catch (Exception e)
            {
                _logger.LogError("显示商品错误",e);
                throw;
            }
        }
    }
}
public class GetGoodsListCommand:IRequest<ApiResult>
{

}
public class GetGoodsListCommandPonse
{
    public int GoodsId { get; set; }
    /// <summary>
    /// 商品名称
    /// </summary>
    public string GoodsName { get; set; } = string.Empty;
}